//
//  M4ProDetailFirstCell.swift
//  M4
//
//  Created by YuChuang on 2024/8/19.
//

import UIKit

enum M4ProDetailStatusAction: Int {
    case M4DetailBankAction = 0
    case M4DetailCheckAction = 1
    case M4DetailPrivacyAction = 2
    case M4DetailAmountAction = 3
}


class M4ProDetailFirstCell: M4BaseTableViewCell {
    
    @IBOutlet weak var M4ProDetailAmount: UILabel!
    
    @IBOutlet weak var M4ProDetailNextLoan: UILabel!
    
    @IBOutlet weak var M4ProDetailBankName: UILabel!
    
    @IBOutlet weak var M4ProDetailBankNumber: UILabel!
    
    @IBOutlet weak var M4ProDetailBankButton: UIButton!
    
    private var bankId: Int = 0
    
    override func awakeFromNib() {
        super.awakeFromNib()
    }
    
    override func M4UpdateDataAndUI() {
        let capital = data as? Int
        M4ProDetailAmount.text = "$\(M4String.M4BlankAmount(original: "\(capital ?? 0)"))"
    }
    
    override func M4SecondDataRefresh() {
        let data = data2 as? M4UserLatestBankData
        M4ProDetailBankName.text = data?.ODpK
        M4ProDetailBankNumber.text = data?.HKcZzMeYYUi
        bankId = data?.YZaWhPDiAj ?? 0
    }
    
    override func M4ThirdDataRefresh() {
        let amount = data3 as? Int
        let text = "La próxima vez puedes cargar: \("$\(M4String.M4BlankAmount(original: "\(amount ?? 0)"))")"
        let range = (text as NSString).range(of: "\("$\(M4String.M4BlankAmount(original: "\(amount ?? 0)"))")")
        let attr = NSMutableAttributedString(string: text)
        attr.addAttribute(.font, value: UIFont.systemFont(ofSize: 13, weight: .medium), range: range)
        attr.addAttribute(.foregroundColor, value: COLOR_00479D, range: range)
        M4ProDetailNextLoan.attributedText = attr
    }
    
    @IBAction func M4ProDetAmountAlertShow(_ sender: UIButton) {
        M4CellActionDelegate?.M4CellAction(M4IDAction(actionType: M4ProDetailStatusAction.M4DetailAmountAction.rawValue))
        sender.M4EventUnavailable = false
    }
    

    @IBAction func M4ProDetailToBankPage(_ sender: UIButton) {
        M4CellActionDelegate?.M4CellAction(M4IDAction(actionType: M4ProDetailStatusAction.M4DetailBankAction.rawValue, actionData: bankId))
        sender.M4EventUnavailable = false
    }
    
}
